<!DOCTYPE html>
<html lang="en">

<head>
    <title>ReportBro Demo Invoice</title>
    <meta charset="utf-8" />
    <link href="/assets/frappe_study/reportbro/reportbro.css" rel="stylesheet" type="text/css" />
    <script src="/assets/frappe_study/reportbro/reportbro.js"></script>
    <style type="text/css">
        html,
        body {
            margin: 0;
            padding: 0;
        }

        @font-face {
            font-family: "HeiTi";
            src: url("/assets/frappe_study/reportbro/fonts/HeiTi.woff2");
        }

        @font-face {
            font-family: "MSYH";
            src: url("/assets/frappe_study/reportbro/fonts/MSYH.ttc");
        }

        @font-face {
            font-family: "simkai";
            src: url("/assets/frappe_study/reportbro/fonts/simkai.ttf");
        }
        
    </style>
    </style>
</head>

<body>
    <div id="reportbro"></div>

    <script type="text/javascript">
        function saveReport() {
            const reportData = rb.getReport();
            console.log(JSON.stringify(reportData));
            return;
            axios.put('url', reportData
            ).then(function (response) {
                // report definition saved successfully,
                // set modified flag to false to disable save button
                rb.setModified(false);
            })
                .catch(function (error) {
                    alert('saving report failed');
                });
        }


        const rb = new ReportBro(document.getElementById('reportbro'), {
            //remove reportServerUrl if you want to use the default report server for a quick start
            reportServerUrl: '/api/method/frappe_study.frappestudy.report_server.run',
            saveCallback: saveReport,
            reportServerHeaders: { "X-Frappe-CSRF-Token": "{{csrf_token}}", "Content-Type": "application/json;charset=utf-8" },
            menuShowButtonLabels: true,
            defaultFont:'simkai',
            additionalFonts: [
            { name: '黑体', value: 'HeiTi'},     
            { name: '微软雅黑', value: 'MSYH'},    
            { name: '楷体', value: 'simkai'},    
        ]
        });
        //rb.load(report);
        fetch('/api/method/frappe_study.frappestudy.print_service.get_doc_withmeta?doc_type=Item&doc_name=1001')
            .then(response => response.json())
            .then(data => {
                // 使用解析后的对象
                console.log(data);
                rb.load(data.message);
            })
            .catch(error => console.error('Error:', error)); 
    </script>
</body>

</html>